from pathlib import Path
import argparse
from moviepy.editor import *

def parse_arguments():
    parser = argparse.ArgumentParser(description="video2gif")
    parser.add_argument('--video_dir', type=str, default="F://打架//temp//myvideo-output")
    parser.add_argument('--video_outdir', type=str, default="F://打架//temp//myvideogif")
    return parser.parse_args()

def main():
    args = parse_arguments()
    video_paths = Path(args.video_dir).glob("*.mp4") 
    for video_path in video_paths:
        #将mp4文件名更改为gif文件名
        gif_file = Path(video_path.name).with_suffix(".gif")
        gif_path = args.video_outdir + "/" + str(gif_file)
        
        #转换成gif
        gif_video = VideoFileClip(str(video_path))
        gif_video = gif_video.fx(vfx.speedx, 2)  # 这会将速度加倍
        
        # 保存gif
        gif_video.write_gif(str(gif_path),fps=30)


if __name__ == "__main__":
    main()
